package 八大排序;

/**
 * 希尔排序：本质是分组之后的插入排序
 * @author 刘学松
 * @date 2021/2/24 20:06
 */
public class 希尔排序 {
    public static void main(String[] args) {
        ArrayUtils.printArray(shellSort(ArrayUtils.array));
    }

    public static int[] shellSort(int[] a) {
        int d = a.length;
        while (d != 0) {
            d = d / 2;
            for (int x = 0; x < d; x++) {
                for (int i = x + d; i < a.length; i += d) {
                    int j = i - d;
                    int temp = a[i];
                    while (j>=0 && temp < a[j]) {
                        a[j + d] = a[j];
                        j -= d;
                    }
                    a[j + d] = temp;
                }
            }
        }
        return a;
    }
}
